package priv.zgh.forum.discuss.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.StringUtils;
import priv.zgh.forum.discuss.entity.Posts;
import priv.zgh.forum.discuss.mapper.PostsMapper;
import priv.zgh.forum.discuss.service.PostsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import priv.zgh.forum.re.entity.ResourcesGame;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZGH
 * @since 2022-03-26
 */
@Service
public class PostsServiceImpl extends ServiceImpl<PostsMapper, Posts> implements PostsService {

    @Override
    public Page<Posts> pageResourcesCondition(long current, long limit, Posts query) {
        Page<Posts> page = new Page<>(current,limit);
        QueryWrapper<Posts> wrapper = new QueryWrapper<>();
        //取出查询封装的数据
        String condition01 = query.getSubject();
        //拼接动态SQL语句
        if(!StringUtils.isEmpty(condition01)){
            //构建条件
            wrapper.like("subject",condition01);
        }
        //根据创建时间排序
        wrapper.orderByDesc("gmt_create");
        //将条件wrapper封装进service进行查询,然后将放回的结果封装进page
        baseMapper.selectPage(page,wrapper);
        return page;
    }
}
